<template>
    <el-container class="home">
        <el-header class="header">
            <TopBar/>
        </el-header>
        <el-container class="main">
            <el-aside width="200px">
                <el-scrollbar :max-height="containerHeight">
                    <!-- 菜单侧栏导航栏 -->
                    <menus></menus>
                </el-scrollbar>
            </el-aside>
            <el-container class="container">
                <el-main>
                    <div>
                        <router-view></router-view>
                    </div>
                </el-main>
                <el-footer class="footer">
                    Footer底部栏
                </el-footer>
            </el-container>
        </el-container>
    </el-container>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useFullscreen } from '@vueuse/core'
import { useState } from '~/hooks/useState'
import { useActions } from '~/hooks/useActions'

//导入菜单组件
import menus from '~/components/layout/menu/index.vue'
import TopBar from '~/components/layout/topbar/index.vue'

const url = ref('https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg')
// 容器高度初始化为0
const containerHeight = ref(0)
//头像图片地址
const avatar = ref("")
const username = ref("")

//菜单控制
const isCollapse = ref(false)

const { isFullscreen, toggle } = useFullscreen()
let userinfo = ref({})

//获取store中state值
const user = useState(['userinfo'])

const storeActions = useActions(['getinfo'])

//在页面挂载后计算高度
onMounted(() => {
    containerHeight.value = document.documentElement.clientHeight;
    // 获取当前浏览器页面高度，赋值给容器高度
    window.addEventListener('resize', () => {
        // 当浏览器窗口大小发生变化时，重新计算容器高度
        containerHeight.value = document.documentElement.clientHeight;
    });

    storeActions.getinfo().then(res => {
        userinfo.value = res
        avatar.value = res.avatar;
        username.value = res.username
    })
})


</script>
<style scoped lang="scss">
@unocss-placeholder

.home {
    width: 100%;
    height: calc(100% - 60px);

    .header {
        height: 60px;
        position: relative;
    }

    .container {
        padding: 15px 20px;
        height: 100%;
        width: 100%;
        box-sizing: border-box;
        background-color: var(--color-content-background);
    }

    .main {
        height: calc(100% - 60px);
        display: flex;
        justify-content: space-between;
    }
}

.footer {
    height: var(--footer-height);
    line-height: var(--footer-height);
    font-family: MicrosoftYaHei;
    font-size: 14px;
    color: #9c9fa3;
    text-align: center;
    background-color: var(--color-background);
    position: absolute;
    bottom: 0;
}
</style>